package com.yayan.xh.service;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.yayan.xh.bean.IntegralBean;
import com.yayan.xh.dao.IIntegralDao;
import com.yayan.xh.dao.IntegralDao;

@Service
public class IntegralService implements IIntegralService {
	
	private IIntegralDao integralDao;
	
	public IntegralService() {
		integralDao = new IntegralDao();
	}

	@Override
	public List<Map<String, Object>> getFrontIntegral(Map<String, String> map) {
		List<Map<String, Object>> result = null;
		try {
			if(null != map.get("shopId") && null != map.get("userId")
					&& !"0".equalsIgnoreCase(map.get("shopId")) && !"0".equalsIgnoreCase(map.get("userId"))) {
				result = integralDao.getIntegralById(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public List<IntegralBean> getBackIntegral(Map<String, String> map) {
		List<IntegralBean> result = null;
		try {
			if(null != map.get("shopId")) {
				result = integralDao.getIntegralBack(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public IntegralBean getBackIntegralByUserId(Map<String, String> map) {
		IntegralBean result = null;
		try {
			if(null != map.get("shopId") && null != map.get("userId")
					&& !"0".equalsIgnoreCase(map.get("shopId")) && !"0".equalsIgnoreCase(map.get("userId"))) {
				result = integralDao.getIntegralBackByUserId(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public boolean modifyIntegral(Map<String, String> map) {
		boolean f = false;
		try {
			if(null != map.get("shopId") && null != map.get("userId") && null != map.get("type")
					&& !"0".equalsIgnoreCase(map.get("shopId")) && !"0".equalsIgnoreCase(map.get("userId"))) {
				if("0".equals(map.get("type"))) {
					f = integralDao.subtractIntegral(map);
				} else {
					f = integralDao.addIntegral(map);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return f;
	}

}
